package org.tang.springcloudvv.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.tang.springcloudvv.base.Result;
import org.tang.springcloudvv.persistence.base.model.User;
import org.tang.springcloudvv.user.service.UserService;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p><em>Created on 2021/12/1 5:44 下午</em></p>
 * 用户相关
 * @author fuzhongtang
 * @since 1.0.1
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/user/getUser")
    public Result getUser(@RequestParam("userName") String userName)
    {
        User user = userService.getUser(userName);
        return Result.of(HttpStatus.OK.value(),HttpStatus.OK.name(),user);
    }
    @PostMapping("/user/testList")
    public Result testList(@RequestParam("userName") String userName)
    {
        List list = new ArrayList();
        for (int i = 0; i < 1000; i++) {
            User user = new User();
            user.setId(i);
            user.setCreateTime(new Date());
            user.setEmail("email@qq.com");
            user.setUserName("Hello"+System.currentTimeMillis());
            user.setPhone("1350000"+System.currentTimeMillis());
            list.add(user);
        }
        try {
            Thread.sleep(900);
        }catch (Exception e)
        {
        }
        return Result.of(HttpStatus.OK.value(),HttpStatus.OK.name(),list);
    }

    @PostMapping("/user/getUsers")
    public Result getUsers(@RequestParam("userName") String userName)
    {
        List<User> list = userService.getUserList(userName);
        return Result.of(HttpStatus.OK.value(),HttpStatus.OK.name(),list);
    }
}
